import os
import subprocess
from optparse import OptionParser
from PIL import Image 

def main(): 

    parser = OptionParser()

    parser.add_option("-i", "--input",
                        dest = "input",
                        help = "input picture file",
                        type = "string",
                        action = "store"
                        )
                        
    parser.add_option("-o", "--output",
                        dest = "output",
                        help = "output directory",
                        type = "string",
                        action = "store"
                        )                        
    
    (options, args) = parser.parse_args()

    def bailout():
        parser.print_help()
        raise SystemExit

    if not options.input or not options.output:
        bailout()
        
    pic_fn = options.output + os.path.basename(options.input)
        
    try: 
		#Relative Path 
        img = Image.open(options.input) 
		
        area = (354, 840, 1854, 2844) 
        img = img.crop(area) 
		
        #Saved in the same relative location 
        img.save(pic_fn) 
		
    except IOError: 
        pass

if __name__ == "__main__": 
    main() 
